package cn.the.angry.tests;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;

import javax.swing.JFrame;

import cn.the.angry.resourcemanager.ResourceManager;
import cn.the.angry.util.GraphicUtils;

public abstract class AbstractTest extends JFrame
{
	//全屏所需
    private final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    private final GraphicsDevice gd = ge.getDefaultScreenDevice();
    protected final BufferedImage backgroundBufferImage;
    protected final BufferedImage foregroundBufferImage;
        
    static
    {
    	try
		{
			Class.forName("cn.the.angry.resourcemanager.ResourceManager");
		}
		catch (ClassNotFoundException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
    
    protected static int WIDTH;
    protected static int HEIGHT;
    
    public AbstractTest()
    {
        super();
        setResizable(false);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setUndecorated(true);
        gd.setFullScreenWindow(this);   //全屏
        WIDTH = getWidth();
        HEIGHT = getHeight();
        backgroundBufferImage=new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
        foregroundBufferImage=new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
        initCanvas();
    }
    
    private void initCanvas()
    {
    	final Graphics2D backgroundG2d=backgroundBufferImage.createGraphics();
    	backgroundG2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    	final Graphics2D foregroundG2d=foregroundBufferImage.createGraphics();
    	foregroundG2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        
        backgroundG2d.setColor(new Color(146, 204, 222));
        backgroundG2d.fillRect(0, 0, AbstractTest.WIDTH, AbstractTest.HEIGHT-318-200);
        GraphicUtils.autoFill(backgroundG2d, ResourceManager.getSkyImage()
                , 0, AbstractTest.HEIGHT-318-200, AbstractTest.WIDTH, AbstractTest.HEIGHT
                , GraphicUtils.AUTOFILLHORIZONTAL);
        //树
        GraphicUtils.autoFill(backgroundG2d, ResourceManager.getParallaxBackgroundImage()
                           , 0, AbstractTest.HEIGHT-400, AbstractTest.WIDTH, AbstractTest.HEIGHT
                           , GraphicUtils.AUTOFILLHORIZONTAL);
        GraphicUtils.autoFill(backgroundG2d, ResourceManager.getParallaxGrassImage()
                           , 0, AbstractTest.HEIGHT-260, AbstractTest.WIDTH, AbstractTest.HEIGHT
                           , GraphicUtils.AUTOFILLHORIZONTAL);
       
        backgroundG2d.drawImage(ResourceManager.getSlingshotRightImage()
                , 200, AbstractTest.HEIGHT-200-ResourceManager.getSlingshotRightImage().getHeight(null)
                , ResourceManager.getSlingshotRightImage().getWidth(null), ResourceManager.getSlingshotRightImage().getHeight(null)
                , null);
        
        foregroundG2d.drawImage(ResourceManager.getSlingshotLeftImage()
                , 200-15, AbstractTest.HEIGHT-200-ResourceManager.getSlingshotRightImage().getHeight(null)-5
                , ResourceManager.getSlingshotLeftImage().getWidth(null), ResourceManager.getSlingshotLeftImage().getHeight(null)
                , null);
        
        //草坪
        GraphicUtils.autoFill(foregroundG2d, ResourceManager.getParallaxGreenGroundImage()
                           , 0, AbstractTest.HEIGHT-230, AbstractTest.WIDTH, AbstractTest.HEIGHT
                           , GraphicUtils.AUTOFILLHORIZONTAL);
        	            
        //大地
        GraphicUtils.autoFill(foregroundG2d, ResourceManager.getGroundImage()
                           , 0, AbstractTest.HEIGHT-200
                           , AbstractTest.WIDTH, AbstractTest.HEIGHT
                           , GraphicUtils.AUTOFILLHORIZONTAL);
        
        backgroundG2d.dispose();
        foregroundG2d.dispose();
    }
}
